require("../../../../@babel/runtime/helpers/Arrayincludes");

var e, t = require("../../../../@babel/runtime/helpers/defineProperty"), a = require("../../../../@babel/runtime/helpers/objectSpread2"), r = getApp().globalData.api, s = require("../../../../utils/util.js");

Page((t(e = {
    data: {
        zizhuPopup: {
            visible: !1,
            showZiZhu: !0
        },
        afterSaleObj: {
            checkerId: null,
            orderId: null,
            type: 0
        },
        orderData: null,
        ordi: "",
        pkginfo: null,
        ordersn:''
    },
    onLoad: function(e) {
        var t = e.ordersn;
        t ? this.setData({
            ordersn: t
        }) : console.log("不能为空");
    },
    onShow: function() {
        this.getOrderDetailsData();
    },
    getOrderDetailsData: function() {
     
        // !e.data.param && e.data.orderData || (e.setData({
        //     orderData: null,
        //     param: ""
        // }),
        var that = this, para = { 
            ordersn: that.data.ordersn,
            openid:wx.getStorageSync('openid')
        }; 
        r.post1("wechat/home/getOrderDetail", para, !0).then(function(t) {  
              var r = t.data;
            // r.gdsItems.forEach(function(e, t) {
            //     e.checkers.forEach(function(e, s) {
            //         var o = a({}, r.gdsItems[t].checkers[s]);
            //         e.selectChecker = o, "9501" == e.bespeakStatus && e.certNo && (e.name = null, e.certNo = null, 
            //         e.bespeakDate = null);
            //     });
            // }), r = e.addTabData(r);


            that.setData({
                orderData: t.data
            });
        }, function(e) {
            wx.switchTab({
                url: "/pages/homepages/homepages"
            });
        });
    },
    addChecker: function(e) {
        var t = e.currentTarget.dataset, a = (t.v1, t.key), r = t.key1;
        console.log(e.currentTarget.dataset);
        var s = "/pages/order/checker-list/checker-list";
        s += "?enterChannel=1", s += "&key1=" + a, s += "&key2=" + r, s += "&suitSex=" + this.data.orderData.gdsItems[a].suitSex, 
        s += "&suitMarried=" + this.data.orderData.gdsItems[a].suitMarried, wx.navigateTo({
            url: s
        });
    },
    dataTimeShow: function(e) {
        var t = e.currentTarget.dataset, a = t.v1, r = t.key, s = t.key1;
        a.ifEdit && (this.data.timek1 = r, this.data.timek2 = s, this.alertComponent("dataList"));
    },
    atTime: function(e) {
        var t = this.data.orderData;
        t.gdsItems[this.data.timek1].checkers[this.data.timek2].selectChecker.bespeakDate = e.detail, 
        this.setData({
            orderData: t
        });
    },
    cancelEdit: function(e) {
        var t = e.currentTarget.dataset, a = t.key, r = t.key1, s = this.data.orderData;
        s.gdsItems[a].checkers[r].ifUnderEditing = !1, s.gdsItems[a].checkers[r].selectChecker = {}, 
        this.setData({
            orderData: s
        });
    },
    changeEdit: function(e) {
        var t = e.currentTarget.dataset, r = t.key, s = t.key1, o = this.data.orderData, n = a({}, o.gdsItems[r].checkers[s]);
        o.gdsItems[r].checkers[s].ifUnderEditing = !0, o.gdsItems[r].checkers[s].selectChecker = n, 
        this.setData({
            orderData: o
        });
    },
    amend: r.throttle(function(e, t) {
        var a = t.currentTarget.dataset, s = a.v, o = a.key, n = a.key1;
        a.type;
        console.log(s.selectChecker), r.postPort("orderDetailsPersonal", s.selectChecker).then(function(t) {
            wx.showToast({
                title: "保存成功",
                icon: "none"
            });
            var a = e.data.orderData, r = a.gdsItems[o].checkers[n], s = a.gdsItems[o].checkers[n].selectChecker, i = e.mergeObj(r, s);
            a.gdsItems[o].checkers[n] = i, a.gdsItems[o].checkers[n].selectChecker = {}, a.gdsItems[o].checkers[n].ifUnderEditing = !1, 
            "9018" == a.status && (a.gdsItems[o].checkers[n].ifEdit = !1), a.status = t.values.status, 
            e.setData({
                orderData: a
            });
        }, function(e) {});
    }, 1e3),
    mergeObj: function(e, t) {
        var r = a({}, e);
        return Object.keys(e).forEach(function(a, s) {
            console.log(a), "id" == a || "ordId" == a || "ordPkgId" == a ? r[a] = e[a] : t[a] && (r[a] = t[a]);
        }), r;
    },
    orderChannel: function(e) {
        var t = "/pages/usercenter/userOrder/order_particulars/order-particulars?orderId=".concat(this.data.ordi), a = e.currentTarget.dataset.countermandid.id, s = this;
        wx.showModal({
            title: "确定要取消预约？",
            content: "取消预约需要跟体检中心确认您是否到检，一般会在7个工作日内完成",
            cancelColor: "#999999",
            confirmColor: "#2199FF",
            success: function(e) {
                e.confirm && r.getPort("cancelAppoint", {
                    rest: a
                }).then(function(e) {
                    "SUCCESS" === e.result ? s.data.orderData.gdsItems.forEach(function(r, o, n) {
                        r.checkers.forEach(function(r, o, n) {
                            r.id === a && (r.ifApplyCancel = e.values.ifApplyCancel, r.ifApplyCancel ? (s.reminder("提交申请成功,通过后可重新填写体检人信息!"), 
                            wx.navigateTo({
                                url: t
                            })) : (s.reminder("申请取消成功!"), wx.navigateTo({
                                url: t
                            })));
                        });
                    }) : s.reminder(e.message[0].message);
                });
            }
        });
    },
    delOrder: function(e) {
        var t = this;
        wx.showModal({
            title: "确定删除订单？",
            content: "删除后将无法再查看此订单信息，请谨慎选择；如有问题请拨打客服热线：".concat(getApp().globalData.tel),
            cancelColor: "#999999",
            confirmColor: "#2199FF",
            success: function(e) {
                e.confirm && r.putPort("delOrader", {
                    rest: t.data.orderData.orderId
                }, !0).then(function(e) {
                    wx.showToast({
                        title: "删除成功",
                        icon: "none",
                        duration: 2e3,
                        mask: !0,
                        success: function() {
                            setTimeout(function() {
                                var e = getCurrentPages();
                                e[e.length - 2].setData({
                                    param: "newData"
                                }), wx.navigateBack({
                                    delta: 1
                                });
                            }, 500);
                        }
                    });
                }, function(e) {});
            }
        });
    },
    runAfterSale: function(e) {
        var t = e.currentTarget.dataset.ord, a = e.currentTarget.dataset.type, r = e.currentTarget.dataset.checkid, s = !0;
        console.log(t.applyType, this.data.afterSaleObj), t.hasOwnProperty("applyStatus") && 2 != a && ("JG01" == t.applyStatus ? ("BG01" == t.applyType && (this.reminder("该订单已提交申请退款"), 
        s = !1), "BG02" == t.applyType && (this.reminder("该订单已提交申请改期"), s = !1), "BG03" == t.applyType && (this.reminder("该订单已提交申请开票"), 
        s = !1), "BG05" == t.applyType && (this.reminder("该订单已提交取消预约"), s = !1)) : "JG02" == t.applyStatus && t.hasOwnProperty("applyType") && "BG02" != t.applyType && ("BG01" == t.applyType && (this.reminder("该订单已退款"), 
        s = !1), "BG02" == t.applyType && (this.reminder("该订单已改期"), s = !1), "BG03" == t.applyType && (this.reminder("该订单已开票"), 
        s = !1))), s && (r ? this.setData({
            "afterSaleObj.orderId": t.orderId,
            "afterSaleObj.type": a,
            "afterSaleObj.checkerId": r.id
        }) : this.setData({
            "afterSaleObj.orderId": t.orderId,
            "afterSaleObj.type": a
        }), 1 == a ? this.handleShow() : this.entertAfterSafe(a));
    },
    runCannel: function() {
        this.handleShow(!0);
    },
    handleShow: function() {
        var e = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
        this.setData({
            "zizhuPopup.visible": !0,
            "zizhuPopup.showZiZhu": !e
        });
    },
    handleCancel: function() {
        this.setData({
            "zizhuPopup.visible": !1
        });
    },
    dialogAfterSafeRefundTap: function() {
        this.handleCancel(), this.entertAfterSafe();
    },
    entertAfterSafe: function(e) {
        var t;
        t = 2 == e ? "/pages/usercenter/userOrder/order_after_sale/order_after_sale?orderId=" + this.data.afterSaleObj.orderId + "&type=" + this.data.afterSaleObj.type + "&checkerId=" + this.data.afterSaleObj.checkerId : "/pages/usercenter/userOrder/order_after_sale/order_after_sale?orderId=" + this.data.afterSaleObj.orderId + "&type=" + this.data.afterSaleObj.type, 
        getApp().pushPage(t);
    },
    buyAgain: function() {
        for (var e = "", t = "", a = this.data.orderData.gdsItems, r = 0; r < a.length; r++) e += "," + a[r].gdsId, 
        t += "," + a[r].gdsNum;
        var s = "/pages/order/place-order/place-order?setId=" + (e = e.substr(1, e.length)) + "&setNumber=" + (t = t.substr(1, t.length));
        getApp().pushPage(s);
    },
    haveCheckTap: function(e) {
        var t = this, a = t.data.orderData.orderId;
        wx.showModal({
            title: "温馨提示",
            content: "你已完成到院体检了吗？",
            cancelColor: "#999999",
            confirmColor: "#2199FF",
            success: function(e) {
                e.confirm && r.getPort("updateStatus4Complete", {
                    rest: a
                }, !0).then(function(e) {
                    if (e.values) {
                        var a = t.data.orderData;
                        a.status = "9015", a.statusName = "已完成";
                        var r = t.addTabData(a);
                        t.setData({
                            orderData: r
                        }), t.reminder("提交成功!");
                    }
                }, function(e) {
                    e.data.hasOwnProperty("result") && "ERROR" == e.data.result && wx.showToast({
                        title: e.data.message[0].message || e.data.message[0].code,
                        icon: "none",
                        duration: 2e3,
                        mask: !0
                    });
                });
            }
        });
    },
    payment: function() {
        this.readPay(this.data.orderData.ordersn);
    },
    routerLingHos: function(e) {
        var t = e.currentTarget.dataset.pkginfo, a = t.domain, r = t.areaCode;
        wx.navigateTo({
            url: "/pages/hospitalinfo/hospitalinfo?domain=".concat(a, "&areaCode=").concat(r)
        });
    },
    routerLingTc: function(e) {
        var t = e.currentTarget.dataset.pkginfo, a = ""; 
        wx.navigateTo({
            url: "/pages/packagedetails/packagedetails?oid="+t.goodsid+"&areaCode="+t.areaCode
        });
    },
    copyCodeTap: function(e) {
        console.log(e.currentTarget.dataset), wx.setClipboardData({
            data: e.currentTarget.dataset.text,
            success: function(e) {
                wx.getClipboardData({
                    success: function(e) {
                        wx.showToast({
                            title: "复制成功"
                        });
                    }
                });
            }
        });
    },
    readPay1: function(e) {
        var t = '{"openId":"'.concat(wx.getStorageSync("openid"), '"}'), a = {
            orderId: e,
            payChannel: getApp().globalData.appInfo.payChannel,
            mchId: getApp().globalData.appInfo.mchId,
            extra: t
        };
       
        r.postPort("payOrder", a, !0).then(function(t) {
            var a = JSON.parse(t.values);
            console.log(a), wx.requestPayment({
                timeStamp: a.payParams.timeStamp,
                nonceStr: a.payParams.nonceStr,
                package: a.payParams.package,
                signType: a.payParams.signType,
                paySign: a.payParams.paySign,
                success: function(t) {
                    "requestPayment:ok" == t.errMsg && wx.navigateTo({
                        url: "/pages/order/pay_succeed/pay_succeed?orderId=" + e
                    });
                },
                fail: function(e) {
                    wx.showToast({
                        title: "支付失败",
                        icon: "none",
                        duration: 2e3,
                        mask: !0
                    });
                },
                complete: function(e) {}
            });
        }, function(e) {
            void 0 !== e.data.result && "ERROR" == e.data.result && wx.showToast({
                title: e.data.message[0].message,
                icon: "none",
                duration: 2e3,
                mask: !0
            });
        });
    },

    readPay: function(e) {
        var para = {
            ordersn: e,
            openid:wx.getStorageSync("openid"),
            // payChannel: a.globalData.appInfo.payChannel,
            // mchId: a.globalData.appInfo.mchId,
            // extra: o,
        };
        r.post1("wechat/mall/order/getwxpay",para, !0).then(function(t) {     
            wx.requestPayment({
                timeStamp: t.data.timeStamp,
                nonceStr: t.data.nonceStr,
                package: t.data.package,
                signType: t.data.signType,
                paySign: t.data.paySign,
                success: function(t) { 
                    "requestPayment:ok" == t.errMsg && wx.redirectTo({
                        url: "/pages/order/pay_succeed/pay_succeed?orderId=" + e
                    });
                },
                fail: function(t) {
                    wx.redirectTo({
                        url: "/pages/usercenter/userOrder/order_particulars/order-particulars?orderId=" + e
                    });
                },
                complete: function(t) {}
            });
        }, function(t) {
            t.data.hasOwnProperty("result") && "ERROR" == t.data.result && wx.showToast({
                title: t.data.message[0].message,
                icon: "none",
                duration: 2e3,
                mask: !0
            });
        });
    },


    
 
    alertComponent: function(e) {
        this.selectComponent("#" + e).powerDrawer();
    }
}, "copyCodeTap", function(e) {
    console.log(e.currentTarget.dataset), wx.setClipboardData({
        data: e.currentTarget.dataset.text,
        success: function(e) {
            wx.getClipboardData({
                success: function(e) {
                    wx.showToast({
                        title: "复制成功"
                    });
                }
            });
        }
    });
}), t(e, "hosMapTap", function() {
    console.log(this.data.orderData);
    var e = this.data.orderData.orgInfo.lat, t = this.data.orderData.orgInfo.lon, a = this.data.orderData.address, r = this.data.orderData.name, o = s.convert2TecentMap(Number(t), Number(e));
    wx.openLocation({
        latitude: o.lat,
        longitude: o.lng,
        name: r,
        address: a
    });
}), t(e, "reminder", function(e) {
    wx.showToast({
        title: e,
        icon: "none",
        duration: 2e3,
        mask: !0
    });
}), t(e, "addTabData", function(e) {
    var t, a = {
        showDelectorder: !1,
        showBuyAgain: !1,
        showCannelOrder: !1,
        showToPayment: !1,
        showToEvaluate: !1,
        showToInvoice: !1,
        showInvoiveDetais: !1,
        showAroundOther: !1,
        showToYuYue: !1,
        showRefund: !1,
        showMap: !1,
        showCannel: !1,
        showChangeTime: !1,
        showInstructions: !1,
        showHaveCheck: !1,
        showTab: !1
    }, r = [ "9Q17", "9Q19", "9Q21", "9Q70", "9317", "9306", "9A22", "9A20", "9QHS" ].includes(e.platSource);
    if (9016 == e.status) a.showDelectorder = !0, e.gdsItems.length > 0 && (a.showBuyAgain = !0); else if (9001 == e.status) r || (a.showCannelOrder = !0, 
    a.showToPayment = !0); else if (9019 == e.status) r || (a.showCannelOrder = !0); else if (9015 == e.status) a.showDelectorder = !0, 
    [ "9Q19", "9Q21" ].includes(e.platSource) || (e.ifInvoice ? a.showInvoiveDetais = !0 : e.ifSupportInvoice && (a.showToInvoice = !0)), 
    e.gdsItems.length > 0 && !e.evaId && (a.showToEvaluate = !0), e.gdsItems.length > 0 && (a.showBuyAgain = !0); else if (9008 == e.status) a.showAroundOther = !0, 
    e.gdsItems.length > 0 && (a.showBuyAgain = !0); else if (9018 == e.status && 0 == e.refundAmount) "9A20" == e.kind || "9A05" == e.kind || r || ("9A20" != e.kind && (a.showMap = !0), 
    "9A22" == e.kind ? a.showCannel = !0 : e.ifFrontRefundShow && (a.showRefund = !0)); else if (9006 != e.status && 9007 != e.status && 9002 == e.status && 0 == e.refundAmount) {
        "9ADW" === e.kind || "9A20" === e.kind || r || (a.showMap = !0), "9A20" == e.kind || "9A05" == e.kind || r || ("9A22" == e.kind ? a.showCannel = !0 : e.ifFrontRefundShow && (a.showRefund = !0)), 
        r || (a.showChangeTime = !0);
        for (var s = [], o = 0; o < e.gdsItems.length; o++) for (var n = 0; n < e.gdsItems[o].checkers.length; n++) {
            var i = e.gdsItems[o].checkers[n].bespeakDate;
            if (i) {
                var d = i.replace(/[^0-9]/gi, "").substring(0, 8), c = parseInt(d);
                s.push(c);
            }
        }
        var l = (t = new Date().toISOString().slice(0, 10).replace(/[^0-9]/gi, "").substring(0, 8), 
        parseInt(t));
        1 == s.every(function(e, t) {
            return e <= l;
        }) ? (console.log("已到检--显示"), a.showHaveCheck = !0) : (a.showHaveCheck = !1, console.log("已到检--隐藏"));
    }
    for (var u in a) if (a[u]) {
        a.showTab = !0;
        break;
    }
    return e.tabShowDic = a, e;
}), t(e, "onlineTap", function() {
    getApp().onlineKeFuTap({
        pagePath: "/pages/usercenter/userOrder/order_particulars/order-particulars"
    });
}), e));